package com.momo.background.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.momo.background.dto.HotelInfoDto;
import com.momo.background.service.HotelInfoService;
import com.momo.background.vo.AdminVo;
import com.momo.background.vo.HotelInfo;
import com.momo.background.vo.IdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping(value = "/background")
public class HotelMessageController {

    @Autowired
    HotelInfoService hotelInfoService;

    @RequestMapping(value = "/SelectALLHotel",method = RequestMethod.POST)
    public Object SelectAllHotelInfo(@RequestBody HotelInfoDto hotelInfoDto){
        PageHelper.startPage(hotelInfoDto.getCurrentPage(),hotelInfoDto.getPageSize());
        List<HotelInfoDto> hotelInfoDtos = hotelInfoService.SelectAllHotel(hotelInfoDto);
        PageInfo<HotelInfoDto> pageInfo=new PageInfo<HotelInfoDto>(hotelInfoDtos);
        System.out.println(pageInfo.getList());
        return pageInfo;
    }

    @RequestMapping(value = "/SelectHotelById",method = RequestMethod.POST)
    public HotelInfoDto SelectHotelByHotelId(@RequestBody HotelInfoDto hotelInfoDto){
        String hotelId = hotelInfoDto.getHotelId();
        List<HotelInfoDto> hotelInfoDtos = hotelInfoService.SelectHotelById(hotelId);
        return hotelInfoDtos.get(0);
    }

    @RequestMapping(value = "/UpdateHotelInfo",method = RequestMethod.POST)
    public boolean UpdateHotelInfo(@RequestBody HotelInfoDto hotelInfoDto){
        Boolean aBoolean = hotelInfoService.UpdateHotelInfo(hotelInfoDto);
        return aBoolean;
    }

    @RequestMapping(value = "/deleteHotelById",method = RequestMethod.POST)
    public boolean deleteHotelById(@RequestBody HotelInfoDto hotelInfoDto){
        String hotelId = hotelInfoDto.getHotelId();
        int rSet= hotelInfoService.deleteHotelById(hotelId);
        if (rSet!=0){
            return true;
        }
        return false;
    }

    @RequestMapping(value = "/insertHotelInfo",method = RequestMethod.POST)
    public boolean insertHotelInfo(@RequestBody HotelInfoDto hotelInfoDto){
        int rSet= hotelInfoService.insertHotelInfo(hotelInfoDto);
        if (rSet>=2){
            return true;
        }
        return false;
    }

    @RequestMapping(value = "/insertRoom",method = RequestMethod.POST)
    public boolean insertRoom(@RequestBody HotelInfo hotelInfo,HttpServletRequest request){
        AdminVo adminVo = (AdminVo) request.getSession().getAttribute("UserInfo");
        String hotelId = adminVo.getHotelId();
        hotelInfo.setHotelid(hotelId);
        int rSet= hotelInfoService.insertRoom(hotelInfo);
        if (rSet==2){
            return true;
        }
        return false;
    }
}
